package com.tzbank.back.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.back.service.MarketOperationService;
import com.tzbank.entity.backstage.MarketOperation;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import lombok.extern.slf4j.Slf4j;
/**
 * 营销运营配置
 * @author 蔡宇钿
 *2018年6月14日
 */
@Slf4j
@RestController
public class MarketOperationController {

	@Autowired
	private MarketOperationService marketOperationService;
	@GetMapping(value = "getlistMarket")
	//查询
	public Map<String, Object> getlistMarket(HttpServletRequest request, @RequestParam(required = false) String target){
		try {
			if (null == target || target.equals("")) {
				return this.marketOperationService.getlistMarket();
			}else {
				return this.marketOperationService.getlistByMarkettarget(target);
			}
			
		} catch (Exception e) {
			log.error("MarketOperationController getlistMarket : ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}
	
	@PostMapping(value = "addMarket")
	// 增加配置
	public Map<String, Object> addLottery(HttpServletRequest request,@RequestBody MarketOperation marketOperation) {
		try {
			return this.marketOperationService.addMarket(marketOperation);
		} catch (Exception e) {
			log.error("MarketOperationController addMarket: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "modifyByMarketautoId")
	// 更新配置
	public Map<String, Object> modifyBylotteryautoId(HttpServletRequest request, @RequestBody MarketOperation marketOperation) {
		try {
			return this.marketOperationService.modifyByMarketautoId(marketOperation);
		} catch (Exception e) {
			log.error("MarketOperationController modifyByMarketautoId: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "deleteByMarketautoId")
	// 通过逻辑方式实现删除
	public Map<String, Object> deleteBylottauto(HttpServletRequest request, @RequestBody MarketOperation marketOperation) {
		try {
			return this.marketOperationService.deleteByMarketautoId(marketOperation);
		} catch (Exception e) {
			log.error("MarketOperationController deleteByMarketautoId: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}
}
